/*
* localStorage 操作封装
* key {string} 键，只有 key 为获取
* value {string, object} 值，有值时为设置
* */
// localStorage

var $local = function (key, value) {
    if (typeof value === 'undefined') {
        return JSON.parse(localStorage.getItem(key) || '{}');
    } else {
        if (typeof value === 'object') {
            localStorage.setItem(key, JSON.stringify(value));
        } else {
            localStorage.setItem(key, value);
        }
    }
}

//  sessionStorage
var $session = function (key, value) {
    if (typeof value === 'undefined') {
        return sessionStorage.getItem(key) ? JSON.parse(sessionStorage.getItem(key)) : '';
    } else {
        if (typeof value === 'object') {
            sessionStorage.setItem(key, JSON.stringify(value));
        } else {
            sessionStorage.setItem(key, value);
        }
    }
}

Array.prototype.remove = function (val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};

export { $local, $session }